<template>
  <div class="addOrEditRules">
    <div class="header-top">
      <div class="head-title" @click="gotoPage()">
        <i class="el-icon-back"></i>创建社群行为规则
      </div>
    </div>
    <div class="content-big">
      <el-form
          ref="form"
          :model="form"
          :rules="rules"
          label-width="120px"
          label-position="left"
      >
          <el-form-item label="标签规则：" prop="name">
            <el-form-item prop="name" label-width="0px">
              客户
              <el-select
                  v-model="queryParams.userName6"
                  placeholder="请选择"
                  style="width: 150px"
                  class="select-right"
                  size="small"
              >
                <el-option
                    v-for="item in typeList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                >
                </el-option>
              </el-select>
              下列群聊时，打上
              <el-select
                  v-model="queryParams.userName6"
                  placeholder="请选择"
                  style="width: 150px"
                  size="small"
              >
                <el-option
                    v-for="item in typeList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                >
                </el-option>
              </el-select>
              标签，移除
              <el-select
                  v-model="queryParams.userName6"
                  placeholder="请选择"
                  style="width: 150px"
                  size="small"
              >
                <el-option
                    v-for="item in typeList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                >
                </el-option>
              </el-select>
              标签
            </el-form-item>

          </el-form-item>
          <el-form-item label="目标客户群：">
            <el-button plain size="small" icon="el-icon-plus" @click="getSelectUser">企微号</el-button>
            <el-button plain size="small">批量选群标签</el-button>
            <el-table
                :data="tableDataList"
                ref="companylabelList"
                @selection-change="handleSelectionChange"
            >
              <el-table-column type="selection" width="70" align="center"/>
              <el-table-column
                  :label="item.label"
                  :align="item.align?item.align:`center`"
                  v-for="(item, index) in tableColumns"
                  :key="index"
                  :prop="item.key"
                  :min-width="item.minWidth ? item.minWidth : ``"
                  :fixed="item.fixed ? item.fixed : false"
                  :show-overflow-tooltip="true"
              >
                <!--用于表格自定义-->
                <template slot-scope="scope">
                  <div v-if="item.key=='name'">
                    <div class="userInfo">
                      <img src="../../../../assets/images/profile.jpg"/>
                      <div class="name">小城红</div>
                      <div class="label">@志新</div>
                    </div>
                  </div>
                  <div class="select-big" v-else-if="item.key=='label'" style="display: flex;align-items: center; justify-content: center">
                    <el-select
                        v-model="queryParams.userName6"
                        placeholder="请选择"
                        style="width: 100px; margin-right: 10px;"
                        size="small"
                    >
                      <el-option
                          v-for="item in groupTypeList"
                          :key="item.id"
                          :label="item.name"
                          :value="item.id"
                      >
                      </el-option>
                    </el-select>
                    <el-button size="small" plain @click="getSearchGroup">选择客户群</el-button>
                      <div style="width: 300px; padding: 0px 10px">
                          <multipleSelect size="small" placeholder='智能标签' class="select-right" :receiverNameOpt='lableOpt' @change="getMultipleSelectlist"></multipleSelect>
                      </div>

                  </div>

                  <div v-else style="text-align: center">{{ scope.row[item.key] }}</div>
                </template>
              </el-table-column>
              <el-table-column
                  fixed="right"
                  label="操作"
                  width="80">
                <template slot-scope="scope">
                  <el-button type="text" size="small">移除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <pagination
                v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList"
            />
          </el-form-item>

      </el-form>
    </div>
    <div class="footer-btn">
      <el-button @click="handleCloseDialog">取消</el-button>
      <el-button type="primary" @click="onSubmit('form')">提交并发送</el-button>
    </div>
    <!--    添加链接-->
    <searchGroup v-if="showSearchGroup" :visableIf.sync="showSearchGroup"></searchGroup>
    <!--    选择企微号-->
    <selectByUser v-if="showSelectByUser" :visableIf.sync="showSelectByUser"></selectByUser>
  </div>
</template>

<script>

import MultipleSelect from "@/views/components/multipleSelect.vue";
import {listUser} from "@/api/system/user";

export default {
  name: 'addOrEditRules',
  components: {
    MultipleSelect,
    'searchGroup': () => import('./searchGroup.vue'),//按群查找
     'selectByUser': () => import('@/views/customerOperationsMgt/circleFriendsMgt/selectByUser.vue'),//导出弹窗
    // 'MultipleSelect': () => import('@/components/MultipleSelect/index.vue'),//导出弹窗
    // 'viewConditions': () => import('./viewConditions.vue'),//导出弹窗
  },
  data() {
    return {
      // 查询参数
      showSearchGroup: false,
      showSelectByUser:false,
      tableHeight: 600,
      tableColumns: [
        {key: 'name', label: `生效企微号`, visible: true, minWidth: 130, fixed: true, align: 'left'},
        {key: 'label', label: `群聊`, visible: true, minWidth: 600, fixed: false},

      ],
      tableDataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,//用户id
        userName1: null,

      },
      total: 8, // 表格的总条数
      active: 0,

      typeList: [
        //性别
        {id: 1, name: "未加入"},
        {id: 2, name: "已加入"},
        {id: 3, name: "退出"},
      ],
      groupList: [
        //有无备注
        {id: 1, name: "已加入常规群"},
        {id: 2, name: "未加入常规群"},
        {id: 3, name: "加入VIP"},
      ],
      pushTimeList: [
        //有无备注
        {id: 1, name: "立即发布"},
        {id: 2, name: "定时发布"},
      ],
      dateRange1: [],
      checked: true,
      form: {
        basicInfo: {
          taskName: null,//任务名称
          groupInfo: null,//分组信息
          enterpriseInfo: {
            //企微号信息
            ids: [],//选择的人员
            useType: 1,//客户范围
            condition: [{
              qwLabel: null,//企微标签
            }]
          }
        }
      },
      lableOpt: [
        {
          value: 1, label: '客户等级', children: [
            {value: 3, label: '核心',},
            {value: 4, label: '重要',},
            {value: 5, label: '一般',}
          ]
        },
        {
          value: 2, label: '客户等级2', children: [
            {value: 6, label: '可爱',},
            {value: 7, label: '知性',},
            {value: 8, label: '性感',}
          ]
        }
      ],
      budgetTypeList: [
        {
          label: '所有客户',
          value: 0,
        },
        {
          label: '筛选客户',
          value: 1,
        }
      ],//
      groupTypeList: [
        //群查找
        {id: 1, name: "选群"},
        {id: 2, name: "选标签"},
      ],
      rules: {
        'basicInfo.taskName': [
          {required: true, message: '请输入任务名称', trigger: 'blur'}
        ],
        'basicInfo.groupInfo': [
          {required: true, message: '请选择分组', trigger: 'blur'}
        ],
        'basicInfo.groupInfo.enterpriseInfo.ids': [
          {required: true, message: '请选择下发的企微号', trigger: 'blur'}
        ],
        'basicInfo.groupInfo.enterpriseInfo.useType': [
          {required: true, message: '请选择客户范围', trigger: 'blur'}
        ],

      },
    }
  },
  created() {
    // this.getList();
    this.tableDataList = [];
    for (let i = 0; i < 10; i++) {
      let obj = {
        name: '小红',
        label: '18207418337',
        operate: true,
      }
      this.tableDataList.push(obj);
    }
  },
  mounted() {
  },
  watch: {},
  methods: {
    getMultipleSelectlist(val) {
      console.log('多选标签的值', val);
    },
      getSelectUser() {
          //选择企微号
          this.showSelectByUser = true;
      },
    getSearchGroup() {
      this.showSearchGroup = true;
    },
    // 多选框选中数据
    handleSelectionChange(val) {
      this.multipleSelection = [];
      if (val && val.length > 0) {
        val.forEach((item) => {
          this.multipleSelection.push(item.id);
        })
        console.log('multipleSelection', this.multipleSelection);
      }
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
            this.tableDataList = response.rows;
            this.total = response.total;
            this.loading = false;
          }
      );
    },
    onSubmit(formName) {
      //提交的代码
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log('提交表单');
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    gotoPage() {
      this.$router.push({
        path: '/IntelligentOperationMgt/inoperationMgt/automaticLabelingMgt',
      })
    },
    handleCloseDialog() {
      this.$emit('update:visableIf', false);
      this.$emit('handleQuery');
    }
  }
}
</script>

<style scoped lang="scss">
.other-option {
  height: 30px;
  display: flex;
  align-items: center;
  color: #2d8cf0;
  font-size: 14px;
  margin-left: 15px;
  border-top: 1px solid #eee;
}

.userInfo {
  border-radius: 4px;
  margin: 8px 0;
  cursor: pointer;
  position: relative;
  padding-left: 50px;
  font-size: 14px;
  list-style: none;
  text-align: left;

  img {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    left: 0px;
    top: 0px;
    position: absolute;
  }

  .label {
    margin-top: 2px;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #f90;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.content-big {
  height: calc(100vh - 150px);
  overflow-y: auto;
  margin: 0 auto;
  background: #fff;
  width: 1050px;
  padding: 20px;
  overflow-x: hidden;
}


.header-top {
  height: 46px;
  background: #fff;
  border-bottom: 1px solid #e9e9e9;
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 20px;

  .head-title {
    font-size: 14px;
    line-height: 22px;
    margin-right: 10px;
    display: flex;
    align-items: center;
    font-weight: bold;

    i {
      font-size: 20px;
      font-weight: bold;
      cursor: pointer;
      margin-right: 10px;
    }
  }

}

.label-list {
  label {
    font-size: 14px;
    line-height: 1.5715;
    word-wrap: break-word;
    font-weight: 400;
  }

  span {
    margin: 4px 4px 4px 0;
    font-size: 12px;
    height: 25px;
    line-height: 25px;
    white-space: nowrap;
    background: #f0f0f0;
    border: 1px solid #e9e9e9;
    border-radius: 4px;
    padding: 0px 7px;
    display: inline-block;

  }
}

/* 通过外部CSS设置编辑器大小 */
::v-deep .ql-editor {
  height: 200px;
}


.footer-btn {
  position: absolute;
  left: 0px;
  right: 0px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
}

.addOrEditRules {
  position: relative;
  padding-bottom: 50px;
}

.el-table {
  margin-top: 10px;
}
</style>
